Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Paratest in GitHub Action #1346

Merged
merged 6 commits into from
Jan 25, 2025
Merged

Use Paratest in GitHub Action #1346

merged 6 commits into from
Jan 25, 2025

Conversation

garrettw
Copy link
Contributor

@garrettw garrettw commented Jan 1, 2025

Integration test step is now down from 23 mins to 9.5 mins on the GitHub Action.

@garrettw garrettw marked this pull request as ready for review January 1, 2025 02:26
@garrettw garrettw changed the title Testing paratest Use Paratest in GitHub Action Jan 1, 2025
Copy link
Member

@BentiGorlich BentiGorlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I execute it locally I get at least this error:

Processes: 12
Runtime: PHP 8.3.15
Configuration: /mbin-repo/phpunit.xml.dist

............................................................. 61 / 1007 ( 6%)
............................................................. 122 / 1007 ( 12%)
............................................................. 183 / 1007 ( 18%)
............................................................. 244 / 1007 ( 24%)
............................................................. 305 / 1007 ( 30%)
............................................................. 366 / 1007 ( 36%)
............................................................. 427 / 1007 ( 42%)
............................................................. 488 / 1007 ( 48%)
............................................................. 549 / 1007 ( 54%)
............................................................. 610 / 1007 ( 60%)
............................................................. 671 / 1007 ( 66%)
............................................................. 732 / 1007 ( 72%)
............................................................. 793 / 1007 ( 78%)
............................................................. 854 / 1007 ( 84%)
...........F................................................. 915 / 1007 ( 90%)
............................................................. 976 / 1007 ( 96%)
............................... 1007 / 1007 (100%)

Time: 02:48.961, Memory: 84.00 MB

There was 1 failure:

  1. App\Tests\Functional\Controller\Entry\EntryEditControllerTest::testAuthorCanEditOwnEntryImage
    Failed asserting that null is not null.

/mbin-repo/tests/Functional/Controller/Entry/EntryEditControllerTest.php:100

FAILURES!
Tests: 1007, Assertions: 18730, Failures: 1.

As I said there are some flaky tests. If you didn't try to run it locally please do that and try it a bunch of times to check if there still are some flaky tests

@garrettw
Copy link
Contributor Author

garrettw commented Jan 1, 2025

I ran it inside my Codespaces container and got no errors. If this is only happening in the Docker setup, I don’t think that should be a blocker if it runs fine elsewhere. Also, please note that this change only affects the GitHub Action (where it also runs fine, as you can see here) and nothing else. You can still run tests the normal way in any environment.

@garrettw garrettw added enhancement New feature or request testing Unit/Functional/Integration test issues and pull requests DX Impacts developer experience labels Jan 1, 2025
@BentiGorlich
Copy link
Member

If it fails on my PC (likely because of the higher thread count) that only highlights that the test code is not thread-safe, which it should be. If it is not it is only a matter of time until a test fails in the workflow

@BentiGorlich
Copy link
Member

BentiGorlich commented Jan 8, 2025

I tried a bunch of things now, but the most I got was 2 consecutive ok runs.
That was with this command:

php vendor/bin/paratest --functional --passthru-php="'-d' 'memory_limit=192M'" tests/Functional -p 4

The --functional limits the parallelization to test classes rather than test cases and the -p 4 limits it to 4 processes (which was the number of processes in the action log of this PR).

The bottom line is that the tests are sadly not thread safe. Most of the issues have to do with image uploads, but not all of them do.

In my mind all tests would have to pass like 100 to 1000 times without any failures to count as thread safe. If you want to pursue this (which I would encourage) I can push a few fixes I already did to this branch. That is up to you though, as I understand (and feel the same way myself) that it is rather tedious work

@garrettw
Copy link
Contributor Author

garrettw commented Jan 9, 2025

Ah, I did forget to try the --functional flag. Good catch.
I do want to try a couple of other parallelization solutions first though, and once I get those working I’ll let you know how to test them.

@BentiGorlich
Copy link
Member

I have an idea on how to still leverage paratest. We can put all non thread-safe tests in a group and then run that group with phpunit and afterwards run all thread-safe tests with paratest. The practice of identifying those tests is very annoying and time consuming I assume, but 🤷

@BentiGorlich
Copy link
Member

BentiGorlich commented Jan 17, 2025

If you want I can do it, but that will take time

…h phpunit

- create a PHPUnit group `NonThreadSafe` which marks tests that should only be serially executed with PHPUnit and not with paratest
- create a new task in the action.yaml for executing tests with paratest
- only execute tests in the group `NonThreadSafe` with PHPUnit
@BentiGorlich BentiGorlich dismissed their stale review January 25, 2025 11:24

Changed code myself

@BentiGorlich BentiGorlich requested a review from melroy89 January 25, 2025 12:07
@@ -101,17 +101,27 @@ jobs:
DATABASE_PORT: 5432
REDIS_HOST: valkey
REDIS_PORT: 6379
run: php bin/phpunit tests/Unit
run: php vendor/bin/paratest --passthru-php="'-d' 'memory_limit=192M'" tests/Unit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the memory limit increase needed for a unit test? no right? You might want to add it to the functional test I guess..?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would the unit test even require a database connection.. I know it might be off-topic for this specific PR, but I don't believe our unit tests are correctly stubbing the Database calls. Which an unit test should do actually

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because they use the same test setup which needs a db connection. We could maybe fix that, but I just ignored to get the tests back up and running.

The memory passthrough might not be needed at all, but I included it, because @garrettw included in his initial PR

@BentiGorlich BentiGorlich merged commit 8acf984 into main Jan 25, 2025
7 checks passed
@BentiGorlich BentiGorlich deleted the paratest branch January 25, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Impacts developer experience enhancement New feature or request testing Unit/Functional/Integration test issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants